package com.jnevision.config;

import com.baomidou.mybatisplus.extension.api.IErrorCode;

/**
 * 错误代码
 * 
 */
public enum ErrorCode implements IErrorCode {

    /**
     * 成功
     */
    SUCCESS(10000L, "成功"),

	/**
     * 未登录
     */
    NO_LOGIN(-2, "未登录");

    private final long code;
    private final String msg;

    ErrorCode(final long code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ErrorCode fromCode(long code) {
        ErrorCode[] cecs = ErrorCode.values();
        for (ErrorCode cec : cecs) {
            if (cec.getCode() == code) {
                return cec;
            }
        }
        return SUCCESS;
    }

    @Override
    public long getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return String.format(" ErrorCode:{code=%s, msg=%s} ", code, msg);
    }

}
